import { createBrowserRouter, redirect } from "react-router-dom"
import Login from "@/pages/login/index.jsx"
import LuckyLayout from "../components/layout"
import Dashboard from "../pages/biss/dashboard"
import Food from "../pages/biss/food"
import Store from "../pages/biss/store"
import Error404 from "../pages/error/404"
import LowCodeConfig from "@/components/low-code/low-code-config/index.tsx"

const routes = [
  {
    path: "/login",
    element: <Login></Login>,
  },
  {
    path: "/",
    element: <LuckyLayout></LuckyLayout>,
    loader: () => {
      const token = localStorage.getItem("token")
      if (!token) {
        throw redirect("/login")
      }
      return null
    },
    children: [
      {
        index: true,
        element: <Dashboard></Dashboard>,
      },
      {
        path: "/store",
        element: <Store></Store>,
      },
      {
        path: "/food",
        element: <Food></Food>,
      },
      {
        path: "/low-code-config",
        element: <LowCodeConfig></LowCodeConfig>,
      },
    ],
  },
  {
    path: "*",
    element: <Error404></Error404>,
  },
]
const router = createBrowserRouter(routes)
export default router
